package com.niit.userinterface;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    String[] contactsArray = {"张三", "李四", "王五", "赵六"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 1.先找到listview,通过findViewById方法
        ListView lv = findViewById(R.id.lv_contact);
        // 2.创建一个Adapter适配器
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, contactsArray);
        // 3.给listview设置适配器
        lv.setAdapter(adapter);


    }
}